//
// Created by Tian on 25-5-10.
//

#include "ui_ctrl.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

#include "lvgl.h"
#include "lv_port_disp.h"
#include "ui.h"
#include "../../../main/include/ble_server.h"
#include "fan.h"


void ui_screen_change_to(int screen)
{
    lv_obj_t * change_screen = NULL;
    switch (screen) {
        case 1:
            change_screen = ui_Screen1;
            break;
        case 2 :
            change_screen = ui_Screen2;
            break;
        default:
            break;
    }
    if (change_screen == NULL)
        return;
    lv_scr_load_anim(change_screen, LV_SCR_LOAD_ANIM_FADE_IN, 300, 0, false);
}


void ui_set_cpu_temperature(int t)
{
    lv_label_set_text_fmt(ui_CPUDATA,"%d", t);
}

void ui_set_fan_rpm(int fan, int rpm)
{
    if(fan)
    {
        lv_label_set_text_fmt(ui_FANDATA,"%d", rpm);
    }
    else{
        lv_label_set_text_fmt(ui_FANDATA,"%d", rpm);
    }
}

void ui_set_fan_pwm_duty(int fan, int duty)
{
    if(fan)
    {
        lv_bar_set_value(ui_DUTYDATA,duty, LV_ANIM_ON);
    }
    else{
        lv_bar_set_value(ui_DUTYDATA,duty, LV_ANIM_ON);
    }
}

void ui_set_device_name(const char* name)
{
    lv_label_set_long_mode(ui_DEVICENAME, LV_LABEL_LONG_SCROLL);
    //lv_label_set_text(ui_DEVICENAME, name);
    lv_label_set_text_static(ui_DEVICENAME, name);
    //lv_label_set_text_fmt(ui_DEVICENAME,"%s", name);
}
